package per.chao.mqtt.domain.protocol.pingreq;

import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.*;
import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import per.chao.mqtt.domain.protocol.BaseProtocolHandler;
import per.chao.mqtt.domain.repo.PubRelMessageRepo;
import per.chao.mqtt.domain.repo.PublishMessageRepo;
import per.chao.mqtt.domain.repo.SessionRepo;
import per.chao.mqtt.domain.repo.SubscribeMessageRepo;
import per.chao.mqtt.domain.shared.store.SessionStore;

/**
 * Description:
 *
 * @author W.Chao
 * @date 2021/6/19 23:05
 **/
@Component
@Slf4j
public class PingReq extends BaseProtocolHandler {

	@Override
	public void handleMessage(Channel channel, Object msg) {
		MqttMessage pingResp = MqttMessageFactory.newMessage(
				new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0),
				null,
				null
		);
		log.info("PINGREQ - clientId: {}", channel.attr(AttributeKey.valueOf("clientId")).get());
		channel.writeAndFlush(pingResp);
	}
}
